package cz.zcu.fav.rat.dataaccess.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cz.zcu.fav.rat.beans.ObjectClass;
import cz.zcu.fav.rat.dataaccess.dao.ObjectClassDAO;
import cz.zcu.fav.rat.dataaccess.service.ObjectClassService;
import cz.zcu.fav.rat.dataaccess.service.ObjectService;

@Service("objectClassService")
@Transactional
public class ObjectClassServiceImpl extends
		GenericDataServiceImpl<ObjectClass, ObjectClassDAO> implements
		ObjectClassService
{
	
	@Autowired
	ObjectService objectService;

	
	@Autowired
	public ObjectClassServiceImpl(ObjectClassDAO dao)
	{
		super(dao);
	}

	@Override
	@Transactional(readOnly = false)
    @Secured("ROLE_ADMIN")
	public void delete(ObjectClass persistentObject)
	{
		objectService.deleteCollection(persistentObject.getObjects());
		persistentObject = merge(persistentObject);
		super.delete(persistentObject);
	}
	
	@Override
	@Transactional(readOnly=true)
	public List<ObjectClass> getObjectClassByName(String name)
	{
		return dao.findObjectClassByName(name);
	}
}
